package com.example.com.skills_utf8;

import com.android.internal.*;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewStub;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class EmptyListViewActivity extends Activity{

	
	 private ListView lv = null;
	    private View vEmpt = null;
	    private ArrayAdapter<String> adapter = null;
	    private List<String> sta = new ArrayList<String>();
	    private View vsLoadView = null;
	    
	    String ListViewItemContent ="";
	    
	    
	    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_empty_listview);
		
		lv = (ListView)findViewById(R.id.lv);
        adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,sta);
        lv.setAdapter(adapter);
        vEmpt=findViewById(R.id.ivEmpt);
        lv.setEmptyView(vEmpt);
        vsLoadView = findViewById(R.id.vsLoadView);
		
        
        
        
        
	}

	 @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	        // TODO Auto-generated method stub
	        menu.add(0, 0, 0, "添加");
	        menu.add(1, 1, 1, "删除");
	        menu.add(2, 2, 2, "清空");
	        return super.onCreateOptionsMenu(menu);
	    }

	 
	 boolean bInflate = false;
	    @Override
	    public boolean onOptionsItemSelected(MenuItem item) {
	        // TODO Auto-generated method stub
	        switch(item.getItemId()){
	        
	        case 0:
	        	ListViewItemContent +="i";
	            sta.add(ListViewItemContent);
	            if( vsLoadView instanceof ViewStub){
	            	vsLoadView = ((ViewStub)vsLoadView).inflate();
	            	//inflate_xml =vsLoadView.inflate();
	            }
	            else{
	            	vsLoadView.setVisibility(View.VISIBLE);
	            	System.out.println(vsLoadView.toString());
	            }
	            
	            break;
	        case 1:
	        	
	            if(sta.size()>0){
	            	sta.remove(sta.size()-1);
	            	vsLoadView.setVisibility(View.GONE);
	            }
	            else{
	            	vsLoadView.setVisibility(View.VISIBLE);
	            }
	            
	            break;
	        case 2:
	            sta.clear();
	        //    vsLoadView.setVisibility(View.VISIBLE); // 进度条
	            
	            break;
	        
	        }
	        adapter.notifyDataSetChanged();
	        return super.onOptionsItemSelected(item);
	    }
	
	
	
	    
	    
	    
}


/*
class EmptyAdapter extends BaseAdapter
{
	
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return null;
	}
	
};
*/
